class ModelStored {
  static final Map<String, dynamic> _map = {};

  static String _getKey(Type type, String? tag) {
    return tag == null ? type.toString() : type.toString() + tag;
  }

  ///保存model
  static T put<T>(T model, {String? tag}) {
    String key = _getKey(T, tag);
    _map.putIfAbsent(key, () => model);
    return find(tag: tag);
  }

  ///获取model
  static T find<T>({String? tag}) {
    String key = _getKey(T, tag);
    if (!_map.containsKey(key)) {
      throw "model没有找到，请确保已添加";
    }
    return _map[key] as T;
  }

  ///删除model
  static void delete<T>({String? tag}) {
    String key = _getKey(T, tag);
    if (_map.containsKey(key)) {
      _map.remove(key);
    }
  }
}
